package com.bingxue.edu.management.education.controller;

import com.bingxue.edu.framework.common.model.PageQuery;
import com.bingxue.edu.framework.common.model.Pagination;
import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.framework.mybatis.query.QueryBuilder;
import com.bingxue.edu.framework.security.ApiResource;
import com.bingxue.edu.management.education.model.query.ArrangeTemplateQuery;
import com.bingxue.edu.management.education.model.req.ArrangeTemplateReq;
import com.bingxue.edu.management.education.model.resp.ArrangeTemplateDetailResp;
import com.bingxue.edu.management.education.model.resp.ArrangeTemplateResp;
import com.bingxue.edu.management.education.service.ArrangeTemplateService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 排课模板
 *
 * @author zq
 * @since 2024/08/22
 */
@Tag(name = "排课模板")
@RestController
@RequestMapping("/education/arrange/template")
@RequiredArgsConstructor
public class ArrangeTemplateController {

    private final ArrangeTemplateService arrangeTemplateService;

    @Operation(summary = "分页查询排课模板")
    @ApiResource("system:biz-rule:manage")
    @GetMapping("/page")
    public Response<Pagination<ArrangeTemplateResp>> page(ArrangeTemplateQuery query, @Validated PageQuery pageQuery) {
        Page<ArrangeTemplateResp> page = arrangeTemplateService.getTemplatePage(query,pageQuery);
        return Response.success(Pagination.of(page));
    }

    @Operation(summary = "查询排课模板列表")
    @ApiResource("system:biz-rule:manage")
    @GetMapping("/list")
    public Response<List<ArrangeTemplateResp>> list(@Validated ArrangeTemplateQuery query) {
        QueryWrapper queryWrapper = QueryBuilder.build(query);
        List<ArrangeTemplateResp> list = arrangeTemplateService.listAs(queryWrapper, ArrangeTemplateResp.class);
        return Response.success(list);
    }

    @Operation(summary = "查询排课模板详情")
    @ApiResource("system:biz-rule:manage")
    @GetMapping("/detail/{id}")
    public Response<ArrangeTemplateDetailResp> detail(@PathVariable String id) {
        return Response.success(arrangeTemplateService.getDetailById(id));
    }

    @Operation(summary = "创建排课模板")
    @ApiResource("system:biz-rule:manage")
    @PostMapping("/create")
    public Response<Void> create(@RequestBody @Validated ArrangeTemplateReq req) {
        arrangeTemplateService.create(req);
        return Response.success();
    }

    @Operation(summary = "更新排课模板")
    @ApiResource("system:biz-rule:manage")
    @PostMapping("/update/{id}")
    public Response<Void> update(@RequestBody @Validated ArrangeTemplateReq req,@PathVariable String id) {
        arrangeTemplateService.updateById(req,id);
        return Response.success();
    }

    @Operation(summary = "删除排课模板")
    @ApiResource("system:biz-rule:manage")
    @PostMapping("/delete/{id}")
    public Response<Void> delete(@PathVariable String id) {
        arrangeTemplateService.delete(id);
        return Response.success();
    }

}
